/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.service.catalogue.importer.extract;

import au.com.bytecode.opencsv.CSVReader;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

/**
 *
 * @author khaleddaham
 */
public class HsaIdVmIdProcessor {

    String csvFilename = "/Users/khaleddaham/NetBeansProjects/sll-servicecatalogue/offers/import/utbudspunkter.csv";
    HashMap<VMCareGiver, String> VMToHSAMap = new HashMap<>();

    /**
     * Parse mapping between VM1.0 id and HSAId
     *
     * @throws UnsupportedEncodingException
     * @throws FileNotFoundException
     * @throws IOException
     */
    public HsaIdVmIdProcessor() throws UnsupportedEncodingException, FileNotFoundException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(csvFilename), "UTF8"));
        CSVReader csvReader = new CSVReader(in);
        String[] row = null;
        while ((row = csvReader.readNext()) != null) {
            String hsaId = row[5];
            VMCareGiver vm = new VMCareGiver();
            vm.setId(row[0]);
            vm.setPartId(row[1]);
            VMToHSAMap.put(vm, hsaId);
        }
    }

    public String getHSAIdForVMId(VMCareGiver vmId) {
        return VMToHSAMap.get(vmId);
    }
}
